home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE10 / CLINIC / OPTGRIDU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-20  |  1.1 KB  |  50 lines

  1. unit OptGridU;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Grids, DBGrids;
  8.  
  9. type
  10.   TDBOptGrid = class(TDBGrid)
  11.   protected
  12.     function GetOptWidth: Integer;
  13.   public
  14.     property OptWidth: Integer read GetOptWidth;
  15.   end;
  16.  
  17. procedure Register;
  18.  
  19. implementation
  20.  
  21. function TDBOptGrid.GetOptWidth: Integer;
  22. var
  23.   Loop: Integer;
  24. begin
  25.   { Vertical scroll bar }
  26.   Result := GetSystemMetrics(sm_CXVScroll);
  27.   { Left and right borders }
  28.   if BorderStyle = bsSingle then
  29.     Inc(Result, 2 * GetSystemMetrics(sm_CXBorder));
  30.   { Each column, possibly including the indicator }
  31.   for Loop := 0 to Pred(ColCount) do
  32.     Inc(Result, Succ(ColWidths[Loop]));
  33.   { Make sure it fits in parent }
  34.   if Parent is TForm then
  35.   begin
  36.     if Result > TForm(Parent).ClientWidth then
  37.       Result := TForm(Parent).ClientWidth;
  38.   end
  39.   else
  40.     if Result > Parent.Width then
  41.       Result := Parent.Width;
  42. end;
  43.  
  44. procedure Register;
  45. begin
  46.   RegisterComponents('Samples', [TDBOptGrid]);
  47. end;
  48.  
  49. end.
  50.